2020-2021 Sunseeker Telemetry and Lighting System
adc10_b_ex1_avccRef.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 #include "driverlib.h"
33 
34 //******************************************************************************
66 //******************************************************************************
67 
68 
69 void main (void)
70 {
71  //Stop WDT
72  WDT_A_hold(WDT_A_BASE);
73 
74  //Set P1.1 as an input pin.
75  /*
76  * Select Port 1
77  * Set Pin 1 as input
78  * Set Ternary module function
79  */
80  GPIO_setAsPeripheralModuleFunctionInputPin(
81  GPIO_PORT_P1,
82  GPIO_PIN1,
83  GPIO_TERNARY_MODULE_FUNCTION);
84 
85  //Set P1.0 as an output pin.
86  /*
87 
88  * Select Port 1
89  * Set Pin 0 as output
90  */
91  GPIO_setAsOutputPin(
92  GPIO_PORT_P1,
93  GPIO_PIN0);
94 
95  //Set P3.5 as an output pin.
96  /*
97 
98  * Select Port 3
99  * Set Pin 5 as output
100  */
101  GPIO_setAsOutputPin(
102  GPIO_PORT_P3,
103  GPIO_PIN5);
104 
105  //Initialize the ADC10B Module
106  /*
107  * Base Address for the ADC10B Module
108  * Use internal ADC10B bit as sample/hold signal to start conversion
109  * USE MODOSC 5MHZ Digital Oscillator as clock source
110  * Use default clock divider of 1
111  */
112  ADC10_B_init(ADC10_B_BASE,
113  ADC10_B_SAMPLEHOLDSOURCE_SC,
114  ADC10_B_CLOCKSOURCE_ADC10OSC,
115  ADC10_B_CLOCKDIVIDER_1);
116 
117  ADC10_B_enable(ADC10_B_BASE);
118 
119  /*
120  * Base Address for the ADC10B Module
121  * Sample/hold for 16 clock cycles
122  * Do not enable Multiple Sampling
123  */
124  ADC10_B_setupSamplingTimer(ADC10_B_BASE,
125  ADC10_B_CYCLEHOLD_16_CYCLES,
126  ADC10_B_MULTIPLESAMPLESDISABLE);
127 
128  //Configure the Memory Buffer
129  /*
130  * Base Address for the ADC10B Module
131  * Use input A1
132  * Use positive reference of AVcc
133  * Use negative reference of AVss
134  */
135  ADC10_B_configureMemory(ADC10_B_BASE,
136  ADC10_B_INPUT_A1,
137  ADC10_B_VREFPOS_AVCC,
138  ADC10_B_VREFNEG_AVSS);
139 
140  ADC10_B_clearInterrupt(ADC10_B_BASE,
141  ADC10IE0);
142 
143  //Enable the Memory Buffer Interrupt
144  ADC10_B_enableInterrupt(ADC10_B_BASE,
145  ADC10IE0);
146 
147  for (;;)
148  {
149  __delay_cycles(5000);
150 
151  //Enable and Start the conversion
152  //in Single-Channel, Single Conversion Mode
153  ADC10_B_startConversion(ADC10_B_BASE,
154  ADC10_B_SINGLECHANNEL);
155 
156  //LPM0, ADC10_ISR will force exit
157  __bis_SR_register(CPUOFF + GIE);
158  __no_operation();
159 
160 
161  }
162 }
163 
164 //ADC10B interrupt service routine
165 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
166 #pragma vector=ADC10_VECTOR
167 __interrupt
168 #elif defined(__GNUC__)
169 __attribute__((interrupt(ADC10_VECTOR)))
170 #endif
171 void ADC10_ISR (void)
172 {
173  switch (__even_in_range(ADC10IV,12)){
174  case 0: break; //No interrupt
175  case 2: break; //conversion result overflow
176  case 4: break; //conversion time overflow
177  case 6: break; //ADC10HI
178  case 8: break; //ADC10LO
179  case 10: break; //ADC10IN
180  case 12: //ADC10IFG0
181  //(Automatically clears ADC10IFG0 by reading memory buffer)
182  if (ADC10_B_getResults(ADC10_B_BASE) < 0x1FF){
183 
184  //Clear P1.0 LED off
185  /*
186 
187  * Select Port 1
188  * Set Pin 0 to output Low.
189  */
191  GPIO_PORT_P1,
192  GPIO_PIN0
193  );
194 
195  //Clear P3.5 LED off
196  /*
197 
198  * Select Port 3
199  * Set Pin 5 to output Low.
200  */
202  GPIO_PORT_P3,
203  GPIO_PIN5
204  );
205 
206  } else {
207  //Set P1.0 LED on
208  /*
209 
210  * Select Port 1
211  * Set Pin 0 to output high.
212  */
214  GPIO_PORT_P1,
215  GPIO_PIN0
216  );
217 
218  //Set P3.5 LED on
219  /*
220 
221  * Select Port 3
222  * Set Pin 5 to output high.
223  */
225  GPIO_PORT_P3,
226  GPIO_PIN5
227  );
228 
229  }
230 
231  //Clear CPUOFF bit from 0(SR)
233  break;
234  default: break;
235  }
236 }
237 
void ADC10_ISR(void)
void main(void)
__no_operation()
__bic_SR_register_on_exit(LPM3_bits|GIE)
GPIO_setOutputHighOnPin(GPIO_PORT_LED1|GPIO_PORT_LED2, GPIO_PIN_LED1|GPIO_PIN_LED2)
GPIO_setOutputLowOnPin(GPIO_PORT_LED1|GPIO_PORT_LED2, GPIO_PIN_LED1|GPIO_PIN_LED2)
__delay_cycles(500000)